import {Game } from './game/game.ts';
import {Direction} from './game/types.ts';
import './css/game.scss';

window.addEventListener('DOMContentLoaded', () => {
    
    // console.log("监听  DOMContentLoaded")
    let game = new Game(500,500,50)
    game.init()

    let run = false;

    window.addEventListener('keydown', (e) => {
        // console.log(e);
        // console.log('监听  keydown',e);
        // console.log(' KeyboardEvent', );
        // console.log(' KeyboardEvent.Code', KeyboardEvent.Code);

        //按下空格开始 或者 暂停游戏
        if(e.code == 'Space'){
            run = !run;
            if(run){
                game.start()
            }else{
                game.pause()
            }
        }else if(e.code =='ArrowUp'){
            game.changeDirection(Direction.Up)
        }else if(e.code =='ArrowDown'){
            game.changeDirection(Direction.Down)
        }else if(e.code =='ArrowLeft'){
            game.changeDirection(Direction.Left)
        }else if(e.code =='ArrowRight'){
            game.changeDirection(Direction.Right)
        }
        
    })

})